#include "queue.h"

int enqueue(queue *que, int net_fd){
    //创建一个新结点
    que_node *new_node = (que_node*)calloc(1,sizeof(que_node));
    new_node->client_fd = net_fd;

    if(que->size == 0){
        //说明当前队列为空
        que->head = new_node;
        que->tail = new_node;
    }else{
        //说明非空
        que->tail->next = new_node;
        que->tail = new_node;
    }
    que->size++; //结点个数加1
    return 0;
}

int dequeue(queue *que){
    if(que->size == 0){
        //队列已经为空，无法删除
        return -1;
    }
    //保存待删结点，head指针先后移动
    que_node *p = que->head;
    que->head = p->next;
    if(que->size == 1){
        //说明当前仅剩一个元素
        que->tail = NULL;
    }
    que->size--; //结点个数减1
    free(p);
    return 0;
}